/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  @endpointMap = {
    ap-northeast-1 = 'indvi.aliyuncs.com',
    ap-northeast-2-pop = 'indvi.aliyuncs.com',
    ap-south-1 = 'indvi.aliyuncs.com',
    ap-southeast-1 = 'indvi.aliyuncs.com',
    ap-southeast-2 = 'indvi.aliyuncs.com',
    ap-southeast-3 = 'indvi.aliyuncs.com',
    ap-southeast-5 = 'indvi.aliyuncs.com',
    cn-beijing = 'indvi.aliyuncs.com',
    cn-beijing-finance-1 = 'indvi.aliyuncs.com',
    cn-beijing-finance-pop = 'indvi.aliyuncs.com',
    cn-beijing-gov-1 = 'indvi.aliyuncs.com',
    cn-beijing-nu16-b01 = 'indvi.aliyuncs.com',
    cn-chengdu = 'indvi.aliyuncs.com',
    cn-edge-1 = 'indvi.aliyuncs.com',
    cn-fujian = 'indvi.aliyuncs.com',
    cn-haidian-cm12-c01 = 'indvi.aliyuncs.com',
    cn-hangzhou-bj-b01 = 'indvi.aliyuncs.com',
    cn-hangzhou-finance = 'indvi.aliyuncs.com',
    cn-hangzhou-internal-prod-1 = 'indvi.aliyuncs.com',
    cn-hangzhou-internal-test-1 = 'indvi.aliyuncs.com',
    cn-hangzhou-internal-test-2 = 'indvi.aliyuncs.com',
    cn-hangzhou-internal-test-3 = 'indvi.aliyuncs.com',
    cn-hangzhou-test-306 = 'indvi.aliyuncs.com',
    cn-hongkong = 'indvi.aliyuncs.com',
    cn-hongkong-finance-pop = 'indvi.aliyuncs.com',
    cn-huhehaote = 'indvi.aliyuncs.com',
    cn-north-2-gov-1 = 'indvi.aliyuncs.com',
    cn-qingdao = 'indvi.aliyuncs.com',
    cn-qingdao-nebula = 'indvi.aliyuncs.com',
    cn-shanghai-et15-b01 = 'indvi.aliyuncs.com',
    cn-shanghai-et2-b01 = 'indvi.aliyuncs.com',
    cn-shanghai-finance-1 = 'indvi.aliyuncs.com',
    cn-shanghai-inner = 'indvi.aliyuncs.com',
    cn-shanghai-internal-test-1 = 'indvi.aliyuncs.com',
    cn-shenzhen = 'indvi.aliyuncs.com',
    cn-shenzhen-finance-1 = 'indvi.aliyuncs.com',
    cn-shenzhen-inner = 'indvi.aliyuncs.com',
    cn-shenzhen-st4-d01 = 'indvi.aliyuncs.com',
    cn-shenzhen-su18-b01 = 'indvi.aliyuncs.com',
    cn-wuhan = 'indvi.aliyuncs.com',
    cn-yushanfang = 'indvi.aliyuncs.com',
    cn-zhangbei-na61-b01 = 'indvi.aliyuncs.com',
    cn-zhangjiakou = 'indvi.aliyuncs.com',
    cn-zhangjiakou-na62-a01 = 'indvi.aliyuncs.com',
    cn-zhengzhou-nebula-1 = 'indvi.aliyuncs.com',
    eu-central-1 = 'indvi.aliyuncs.com',
    eu-west-1 = 'indvi.aliyuncs.com',
    eu-west-1-oxs = 'indvi.aliyuncs.com',
    me-east-1 = 'indvi.aliyuncs.com',
    rus-west-1-pop = 'indvi.aliyuncs.com',
    us-east-1 = 'indvi.aliyuncs.com',
    us-west-1 = 'indvi.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('indvi', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetDetectionResultRequest {
  detectPath?: string(name='DetectPath'),
  imageUrl?: string(name='ImageUrl'),
  platformType?: string(name='PlatformType'),
}

model GetDetectionResultResponseBody = {
  code?: string(name='Code'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  result?: string(name='Result'),
  success?: boolean(name='Success'),
}

model GetDetectionResultResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetDetectionResultResponseBody(name='body'),
}

async function getDetectionResultWithOptions(request: GetDetectionResultRequest, runtime: Util.RuntimeOptions): GetDetectionResultResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.detectPath)) {
    query['DetectPath'] = request.detectPath;
  }
  if (!Util.isUnset(request.imageUrl)) {
    query['ImageUrl'] = request.imageUrl;
  }
  if (!Util.isUnset(request.platformType)) {
    query['PlatformType'] = request.platformType;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetDetectionResult',
    version = '2019-07-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getDetectionResult(request: GetDetectionResultRequest): GetDetectionResultResponse {
  var runtime = new Util.RuntimeOptions{};
  return getDetectionResultWithOptions(request, runtime);
}

